package com.cloud.form.api.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cloud.form.api.bean.Assembly;
import com.cloud.form.api.service.FormDragerService;
import com.cloud.form.common.result.Quokka;

@RestController
@RequestMapping("/form/api/formdrager")
public class FormDragerController {

	@Autowired
	private FormDragerService formDragService;

	@RequestMapping("assemblies")
	public Quokka listAssemblies() {
		return new Quokka(true, formDragService.listAssemblies());
	}

	@RequestMapping("loadformassemblies")
	public Quokka loadAssembliesByFormId(Long formId, Long actDefId) {
		return new Quokka(true, formDragService.loadFormAssemblies(formId, actDefId));
	}

	@RequestMapping("createassembly")
	public Quokka createAssembly(@RequestBody Assembly assembly) {
		return new Quokka(true, formDragService.createAssemby(assembly));
	}

	@RequestMapping("moveassembly")
	public Quokka move(long id, int x, int y) {
		formDragService.move(id, x, y);
		return new Quokka(true);
	}

	@RequestMapping("saveassemblies")
	public Quokka saveAddemblies(@RequestBody List<Assembly> assemblies) {
		formDragService.saveAssemblies(assemblies);
		return new Quokka(true);
	}

	@RequestMapping("delete")
	public Quokka delete(long id) {
		formDragService.delete(id);
		return new Quokka(true);
	}

	@RequestMapping("clear")
	public Quokka clear(long formId) {
		formDragService.clear(formId);
		return new Quokka(true);
	}


}
